package com.Java.train.common.context;

import com.Java.train.common.response.MemberLoginResp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class LoginMemberContext {
    private static final Logger LOG = LoggerFactory.getLogger(LoginMemberContext.class);

    private static ThreadLocal<MemberLoginResp> member = new ThreadLocal<>();

    public static void setMember(MemberLoginResp memberLoginResp){
        LoginMemberContext.member.set(memberLoginResp);
    }

    public static MemberLoginResp getMember(){
        return member.get();
    }

    public static Long getId(){
        try{
            return member.get().getId();
        } catch (Exception e){
            LOG.error("获取会员登录异常：{}", e);
            throw e;
        }
    }
}
